﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FormsTest
{
    //UPGRADE_NOTE: Field 'EnclosingInstance' was added to class 'EnterSomethingDialog' to access its enclosing instance. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1019'"
    /// <summary> This dialog displays a number of text lines and a text field.
    /// The text field can either be plain text or a password field.
    /// </summary>
    public partial class EnterSomethingDialog : Form
    {
        private LoginMain parent;
        private string[] content;
        internal bool isPassword;
        internal System.String answer;
        static private System.Int32 state11;

        public EnterSomethingDialog()
        {
            InitializeComponent();
        }

        public EnterSomethingDialog(LoginMain parent, System.String title, System.String[] content, bool isPassword)
            : this()
        {
            // TODO: Complete member initialization
            this.parent = parent;
            this.content = content;
            this.isPassword = isPassword;

            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
            this.ShowInTaskbar = false;
            this.Owner = parent;
            this.Text = title;

            for (int i = 0, j = 0; i < content.Length; i++)
            {
                if ((content[i] == null) || ((System.Object)content[i] == (System.Object)""))
                    continue;
                System.Windows.Forms.Label contentLabel = new System.Windows.Forms.Label();
                contentLabel.Text = content[i];
                contentLabel.AutoSize = true;
                panel.Controls.Add(contentLabel);
                contentLabel.Left = 15 + panel.AutoScrollPosition.X;
                contentLabel.Top = (15 * ++j) + panel.AutoScrollPosition.Y;
                if (isPassword)
                {
                    panel.Controls.Add(passwordField);
                    passwordField.Left = 15 + contentLabel.Left + contentLabel.Width;
                    passwordField.Top = contentLabel.Top;
                    passwordField.KeyDown += new System.Windows.Forms.KeyEventHandler(In_KeyDown);
                }
                else
                {
                    panel.Controls.Add(answerField);
                    answerField.Left = 15 + contentLabel.Left + contentLabel.Width;
                    answerField.Top = contentLabel.Top;
                    answerField.KeyDown += new System.Windows.Forms.KeyEventHandler(In_KeyDown);
                }
            }
        }

        //public void keyTyped(object sender, KeyPressEventArgs e)
        //{
        //    //UPGRADE_TODO: The equivalent in .NET for method 'java.awt.event.KeyEvent.getKeyChar' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
        //    if (e.KeyChar == '\n')
        //        this.finish();
        //}

        //private static void keyPressed(object sender, KeyEventArgs e)
        //{
        //}

        //private static void keyReleased(object sender, KeyEventArgs e)
        //{
        //}

        private static void keyDown(object sender, KeyEventArgs e)
        {
            state11 = ((int)System.Windows.Forms.Control.MouseButtons | (int)System.Windows.Forms.Control.ModifierKeys);
        }

        private void finish()
        {
            if (isPassword)
                answer = new System.String(passwordField.Text.ToCharArray());
            else
                answer = answerField.Text;
            //Dispose();
            this.Close();
        }

        private void In_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                finish();
        }
    }
}
